#include "FreeWaySerSender.h"
#include "FreeWaySender.h"
#include "FreeWayEntry.h"
#include "FreeWayMgr.h"
#include <unistd.h>

void FreeWaySerSender::svc()
{

    LOG(INFO) << "FreeWaySender(Server) thread joined";
     while(run)
     {
         if(!msgQueue.empty()){
                msgStruct1 * msgptr = msgQueue.front();

                 LOG(INFO) << "Send" << msgptr->msgPtr;
                //send
                //send version 1: broadcast
                 std::map<std::string,client> &clients = m_mgrptr->getClients();
                for(std::map<std::string,client>::iterator itr = clients.begin();
                itr != clients.end(); ++itr)
                {
                    client cli = itr->second;
                    entry->fwSend(msgptr->msgPtr,msgptr->len,&cli);


                }



                //send success


                //pop message
                lock(0);

                msgQueue.pop();

                unlock(0);
         }
         else{
            sleep(1);
         }


     }


}
